﻿using DotNetty.Buffers;
using DotNetty.Transport.Channels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestNetty.Service.Model;

namespace TestNetty.Service.Handlers
{
    public class ReceptionHandler : ChannelHandlerAdapter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="message">客户端发来的消息</param>
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var receiveMessage = message as MyMessage;
            if (receiveMessage == null)
            {
                return;
            }
            Console.WriteLine($"客户端发来的数据: {receiveMessage.Content}");
            MyMessage myMessage = new MyMessage();

            

            // 响应消息，这里只是简单地返回收到的消息作为示例。  
            MyMessage response = new MyMessage { Id = 1, Content = receiveMessage.Content };
            context.WriteAndFlushAsync(response);
        }
            
    }
}
